<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>奉孝的测开日记</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  
  
    <link rel="alternate" href="/blog/atom.xml" title="奉孝的测开日记" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
    
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.min.css">

  
  
    
<link rel="stylesheet" href="/blog/localshare/css/share.css">

  
  
  
<meta name="generator" content="Hexo 5.4.2"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">奉孝的测开日记</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/blog/" id="subtitle">开启自我改变的原动力</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        
          <a class="main-nav-link" href="/blog/."><i class="fa fa-home"></i> 首页</a>
        
          <a class="main-nav-link" href="/blog/archives/"><i class="fa fa-archive"></i> 归档</a>
        
          <a class="main-nav-link" href="/blog/about/"><i class="fa fa-user"></i> 关于</a>
        
      </nav>
    </div>
    <div id="search-form">
      <div id="result-mask" class="hide"></div>
      <label><input id="search-key" type="text" autocomplete="off" placeholder="搜索"></label>
      <div id="result-wrap" class="hide">
        <div id="search-result"></div>
      </div>
      <div class="hide">
        <template id="search-tpl">
          <div class="item">
            <a href="/{path}" title="{title}">
              <div class="title">{title}</div>
              <div class="time">{date}</div>
              <div class="tags">{tags}</div>
            </a>
          </div>
        </template>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main">
  <article id="spring-SpringBoot入门" class="h-entry article article-type-spring" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog/2022/07/19/SpringBoot%E5%85%A5%E9%97%A8/">Boot入门</a>
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2022-07-19T09:45:51.000Z" itemprop="datePublished">2022年07月19日</time>
</span>
      
      
      
<a href="/blog/2022/07/19/SpringBoot%E5%85%A5%E9%97%A8/#comments" class="article-comment-link">
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="创建项目"><a href="#创建项目" class="headerlink" title="创建项目"></a>创建项目</h1><h1 id="启动方式"><a href="#启动方式" class="headerlink" title="启动方式"></a>启动方式</h1><h1 id="文件目录介绍"><a href="#文件目录介绍" class="headerlink" title="文件目录介绍"></a>文件目录介绍</h1><h3 id="工程目录"><a href="#工程目录" class="headerlink" title="工程目录"></a>工程目录</h3><ul>
<li>/src/main/java 源代码文件</li>
<li>/src/main/resources 所有的资源文件，包括静态资源文件、配置文件、页面文件等<ul>
<li>/src/main/resources/static 用于存放各类静态资源</li>
<li>/src/main/resources/templates 用于存放模版文件</li>
<li>/src/main/resources/application.properties 配置文件。默认支持两种配置文件类型（.properties和.yml）</li>
</ul>
</li>
<li>/src/test/java 单元测试类java代码</li>
<li>/target 编译后的class文件和配置文件等<h3 id="知识点"><a href="#知识点" class="headerlink" title="知识点"></a>知识点</h3>Spring Boot将很多配置文件进行了统一管理，且配置了默认值。<br>自动在/src/main/resources目录下找application.properties文件，找到后运用文件中的配置，否则使用默认配置。<br>.properties和.yml可以同时存在，.yml不支持@PropertySource注解倒入配置。  </li>
<li><em>注意</em>*<br>.properties优先于.yml<h3 id="入口类"><a href="#入口类" class="headerlink" title="入口类"></a>入口类</h3>入口类的类名是根据项目名称生成的，入口类的类名是项目名称+Applicatio  </li>
<li>@SpringBootApplication：是一个组合注解，包含@EnableAutoConfiguration、@ComponentScan和@SpringBootConfiguration三个注解，是项目启动注解</li>
<li>@SpringApplication.run：应用程序开始运行的方法<h3 id="pom文件"><a href="#pom文件" class="headerlink" title="pom文件"></a>pom文件</h3></li>
<li>spring-boot-starter-parent：是一个特殊的starter，用来提供相关的Maven默认依赖，使用它之后，常用的包依赖可以省去version标签。</li>
<li>spring-boot-starter-web：只要将其加入项目的Maven依赖中，我们就得到了一个可执行的Web应用。该依赖中包含许多常用的依赖包，比如spring-web、spring-webmvc等。我们不需要做任何Web配置，便能获得相关Web服务。</li>
<li>spring-boot-starter-test：这个依赖和测试相关，只要引入它，就会把所有与测试相关的包全部引入。</li>
<li>spring-boot-maven-plugin：这是一个Maven插件，能够以Maven的方式为应用提供Spring Boot的支持，即为Spring Boot应用提供了执行Maven操作的可能。能够将Spring Boot应用打包为可执行的jar或war文件。</li>
</ul>
<h1 id="Maven-Helper插件"><a href="#Maven-Helper插件" class="headerlink" title="Maven Helper插件"></a>Maven Helper插件</h1><h3 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h3><p>可以方便查看Maven依赖树的插件，支持多种视图来查看Maven依赖，同时可以帮助我们分析pom文件中的依赖是否存在冲突，方便快速定位错误</p>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><p>【File】→【Settings】→【Plugins】，在搜索框中输入【Maven Helper】，【File】→【Settings】→【Plugins】，在搜索框中输入【Maven Helper】</p>
<h3 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h3><p>打开pom文件，除了Text视图外，多了一个Dependency Analyzer视图  </p>
<img src="/blog/2022/07/19/SpringBoot%E5%85%A5%E9%97%A8/maven-helper.png" class="" title="deploy">  
<ul>
<li>All Dependencies as List：以列表方式显示所有依赖包</li>
<li>All Dependencies as Tree：以树形方式显示所有依赖包</li>
<li>Conflicts：查看所有有冲突的依赖包，如果存在冲突，就会显示红色，同时会显示在右侧视图。我们可以单击有冲突的包，右击【Exclude】来排除冲突，通过右击【Jump To Source[F12]】可以跳转到源代码</li>
</ul>
<h1 id="集成MySQL数据库"><a href="#集成MySQL数据库" class="headerlink" title="集成MySQL数据库"></a>集成MySQL数据库</h1><h2 id="集成MySQL"><a href="#集成MySQL" class="headerlink" title="集成MySQL"></a>集成MySQL</h2><h3 id="引入依赖"><a href="#引入依赖" class="headerlink" title="引入依赖"></a>引入依赖</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;mysql&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>mysql-connector-java：MySQL连接Java的驱动程序。</li>
<li>spring-boot-starter-jdbc：支持通过JDBC连接数据库.<h3 id="添加数据库配置"><a href="#添加数据库配置" class="headerlink" title="添加数据库配置"></a>添加数据库配置</h3>application.properties文件中添加如下的配置信息  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springbootdemo</span><br><span class="line">spring.datasource.username=root</span><br><span class="line">spring.datasource.password=12345678</span><br><span class="line">spring.datasource.driver-class-name=com.mysql.jdbc.Driver</span><br></pre></td></tr></table></figure>
<h3 id="设计表和实体"><a href="#设计表和实体" class="headerlink" title="设计表和实体"></a>设计表和实体</h3>表设计好之后，在com.example.springbootdemo.model下新建实体类  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">package com.example.springbootdemo.model;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 描述：用户表</span><br><span class="line"> * @Author fengxiao</span><br><span class="line"> * @date 2022/07/20</span><br><span class="line"> */</span><br><span class="line">public class AyUser &#123;</span><br><span class="line">    private Integer id;</span><br><span class="line">    private String name;</span><br><span class="line">    private String password;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="集成测试"><a href="#集成测试" class="headerlink" title="集成测试"></a>集成测试</h2><h3 id="测试用例"><a href="#测试用例" class="headerlink" title="测试用例"></a>测试用例</h3>在项目的单元测试类MySpringBootApplicationTests.java中添加如下代码  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">@SpringBootTest</span><br><span class="line">class SpringBootDemoApplicationTests &#123;</span><br><span class="line"></span><br><span class="line">    @Resource</span><br><span class="line">    private JdbcTemplate jdbcTemplate;</span><br><span class="line"></span><br><span class="line">    @Test</span><br><span class="line">    void mySqlTest() &#123;</span><br><span class="line">        String sql = &quot;select id,name,password from ay_user&quot;;</span><br><span class="line">        List&lt;AyUser&gt; userList = (List&lt;AyUser&gt;) jdbcTemplate.query(sql, new RowMapper&lt;AyUser&gt;() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public AyUser mapRow(ResultSet rs, int rowNum) throws SQLException&#123;</span><br><span class="line">                AyUser user = new AyUser();</span><br><span class="line">                user.setId(rs.getInt(&quot;id&quot;));</span><br><span class="line">                user.setName(rs.getString(&quot;name&quot;));</span><br><span class="line">                user.setPassword(rs.getString(&quot;password&quot;));</span><br><span class="line">                return user;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        System.out.println(&quot;查询成功：&quot;);</span><br><span class="line">        for (AyUser user:userList) &#123;</span><br><span class="line">            System.out.println(&quot;【id】:&quot; + user.getId() + &quot;；【name】:&quot; + user.getName());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">* JdbcTemplate：是一个通过JDBC连接数据库的工具类.</span><br><span class="line">* @Resource：自动注入，通过这个注解，在项目启动之后，Spring Boot会帮助我们实例化一个JdbcTemplate对象，省去初始化工作。</span><br><span class="line">* query()方法：JdbcTemplate对象中的查询方法，通过传入SQL语句和RowMapper对象可以查询出数据库中的数据</span><br><span class="line">* RowMapper对象：RowMapper对象可以将查询出的每一行数据封装成用户定义的类，在上面的代码中，通过调用RowMapper中的mapRow方法，将数据库中的每一行数据封装成AyUser对象，并返回</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 集成Druid</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 介绍</span></span></span><br><span class="line">Druid是阿里巴巴开源项目中的一个数据库连接池。Druid是一个JDBC组件，包括三部分：  </span><br><span class="line">① DruidDriver代理Driver，能够提供基于Filter-Chain模式的插件体系；  </span><br><span class="line">② DruidDataSource高效可管理的数据库连接池  </span><br><span class="line">③SQLParser，支持所有JDBC兼容的数据库，包括Oracle、MySQL、SQL Server等  </span><br><span class="line">Durid在监控、可扩展、稳定性和性能方面具有明显的优势，通过其提供的监控功能可以观察数据库连接池和SQL查询的工作情况，</span><br><span class="line">使用Druid连接池可以提高数据库的访问性能</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 引入依赖</span></span></span><br><span class="line">```shell</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;com.alibaba&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;druid&lt;/artifactId&gt;</span><br><span class="line">    &lt;version&gt;1.1.13&lt;/version&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<h3 id="Druid配置"><a href="#Druid配置" class="headerlink" title="Druid配置"></a>Druid配置</h3></li>
</ul>
<h1 id="Spring-Data-JPA"><a href="#Spring-Data-JPA" class="headerlink" title="Spring Data JPA"></a>Spring Data JPA</h1><h2 id="介绍-1"><a href="#介绍-1" class="headerlink" title="介绍"></a>介绍</h2><h2 id="集成"><a href="#集成" class="headerlink" title="集成"></a>集成</h2><h3 id="引入依赖-1"><a href="#引入依赖-1" class="headerlink" title="引入依赖"></a>引入依赖</h3>
        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="http://haohongbin.gitee.io/blog/page/2/index.html">http://haohongbin.gitee.io/blog/page/2/index.html</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
      
    </footer>
  </div>
</article>


  <article id="post-Java面向对象编程" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog/2022/07/15/Java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/">Java面向对象编程</a>
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2022-07-15T09:59:47.000Z" itemprop="datePublished">2022年07月15日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/blog/categories/Java/">Java</a>
  </div>

      
      
<a href="/blog/2022/07/15/Java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/#comments" class="article-comment-link">
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="类"><a href="#类" class="headerlink" title="类"></a>类</h1><h2 id="初类和对象"><a href="#初类和对象" class="headerlink" title="初类和对象"></a>初类和对象</h2><p>使用new操作符，可以创建一个类的实例/对象（ instance/object ）</p>
<h3 id="认识点操作符"><a href="#认识点操作符" class="headerlink" title="认识点操作符"></a>认识点操作符</h3><ul>
<li>点操作符用来访问/操作前面实体的属性</li>
</ul>
<h2 id="引用类型"><a href="#引用类型" class="headerlink" title="引用类型"></a>引用类型</h2><h3 id="引用数据类型和基本数据类型"><a href="#引用数据类型和基本数据类型" class="headerlink" title="引用数据类型和基本数据类型"></a>引用数据类型和基本数据类型</h3><ul>
<li>相同点<ul>
<li>都可以用来创建变量</li>
<li>变量本身都是一个地址</li>
</ul>
</li>
<li>不同点<ul>
<li>基本类型变量的值，就是地址对应的值。引用数据类型的值还是一个地址，需要通过二级跳找到实例</li>
<li>引用数据类型是Java的一种内部类型，是对所有自定义类型和数组引用的统称，并非特指某种类型<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String[] args)&#123;</span><br><span class="line">        // &gt;&gt; TODO m1是一个Merchandise类型的引用，只能指向Merchandise类型的实例</span><br><span class="line">        // &gt;&gt; TODO 引用数据类型变量包含两部分信息：类型和实例。也就是说，</span><br><span class="line">        //    TODO 每一个引用数据类型的变量（简称引用），都是指向某个类（ class /自定义类型）</span><br><span class="line">        //    TODO 的一个实例/对象（instance / object）。不同类型的引用在Java的世界里都是引用。</span><br><span class="line">        // &gt;&gt; TODO 引用的类型信息在创建时就已经确定，可以通过给引用赋值，让其指向不同的实例.</span><br><span class="line">        //         比如 m1 就是Merchandise类型，只能指向Merchandise的实例。</span><br><span class="line">        Merchandise m1;</span><br><span class="line">        m1 = new Merchandise(); // m1本身就是地址</span><br><span class="line">        Merchandise m2 = new Merchandise();</span><br><span class="line">        Merchandise m3 = new Merchandise();</span><br><span class="line">        // &gt;&gt; TODO 给一个引用赋值，则两者的类型必须一样。m5可以给m1赋值，因为他们类型是一样的</span><br><span class="line">        m1 = m3;</span><br><span class="line"></span><br><span class="line">        System.out.println(&quot;m1=&quot; + m1);</span><br><span class="line">        System.out.println(&quot;m2=&quot; + m2);</span><br><span class="line">        System.out.println(&quot;m3=&quot; + m3);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">* 使用new创建一个类的实例。在JAVA程序运行的时候，所有创建出来的实例都被JAVA放在内存里一个叫做堆(heap)的、类似公告栏的地方</span><br><span class="line">* 创建一个实例，就是根据类的定义，点出需要的&quot;纸&quot;，订成一个本子，挂在公告栏上。实例本身，可以认为是这个本子</span><br><span class="line">* 引用里存放的，相当于某个本子坐在公告栏的位置</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 类、对象和引用的关系</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 类和对象的关系</span></span></span><br><span class="line">* 类是对象的模版，对象是类的一个实例</span><br><span class="line">* 一个java程序中类名不会重名</span><br><span class="line">* 一个类可以有很多对象</span><br><span class="line">* 一个对象只能根据一个类来创建</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 引用、类、对象的关系</span></span></span><br><span class="line">* 引用必须是一个类的引用</span><br><span class="line">* 引用只能指向其所属的类型的类的对象</span><br><span class="line">* 相同类型的引用之间可以赋值</span><br><span class="line">* 只能通过指向一个对象的引用，来操作一个对象，比如访问某个成员变量</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 认识数组类型</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 数组是一种特殊的类</span></span></span><br><span class="line">* 数组的类名就是类型带上[]</span><br><span class="line">* 同一类型的数组，每个数组对象的大小可以不一样。也就是每个数组对象占用的内存可以不一样，这和类的对象不同</span><br><span class="line">* 可以用引用指向类型相同、大小不同的数组，因为它们属于同一种类型</span><br><span class="line">```shell</span><br><span class="line">// &gt;&gt; TODO “数组变量”其背后真身就是引用。数组类型就是一种特殊的类。</span><br><span class="line">// &gt;&gt; TODO 数组的大小不决定数组的类型，数组的类型是只是由元素类型决定的。</span><br><span class="line">int[] a1 = new int[9];</span><br><span class="line">int[] a2 = new int[0];</span><br><span class="line">a2 = a1;</span><br><span class="line">// 这个数组的元素就是二维的double数组，既double[][]</span><br><span class="line">double[][][] double3DArray = new double[2][3][4];</span><br></pre></td></tr></table></figure>
<h3 id="引用数组"><a href="#引用数组" class="headerlink" title="引用数组"></a>引用数组</h3></li>
</ul>
</li>
<li>可以把类名当成自定义类型，定义引用的数组，甚至多维数组<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String[] args)&#123;</span><br><span class="line">        Merchandise[] merchandises = new Merchandise[9];</span><br><span class="line">        merchandises[0] = new Merchandise();</span><br><span class="line">        merchandises[1] = new Merchandise();</span><br><span class="line">        merchandises[0].name = &quot;笔记本&quot;;</span><br><span class="line">        System.out.println(merchandises[0].name); // 笔记本</span><br><span class="line">        System.out.println(merchandises[2]); // null</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="引用的缺省值-null"><a href="#引用的缺省值-null" class="headerlink" title="引用的缺省值-null"></a>引用的缺省值-null</h3></li>
<li>null是引用类型的缺省值</li>
<li>null代表空，不存在</li>
<li>引用类型的数组创建出来，初始值都是空<h4 id="null带来的问题"><a href="#null带来的问题" class="headerlink" title="null带来的问题"></a>null带来的问题</h4></li>
<li>NullPointerException</li>
<li>如果不确定，使用前要先判断引用是不是空<br>通过null理解引用的”二级跳”  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String[] args)&#123;</span><br><span class="line">        // 数组在创建出来之后，会按照类型给数组中的每个元素赋缺省值。</span><br><span class="line">        // 引用类型的缺省值是null</span><br><span class="line">        Merchandise[] merchandises = new Merchandise[9];</span><br><span class="line">        // 给索引为0的引用赋值</span><br><span class="line">        merchandises[0] = new Merchandise();</span><br><span class="line">        // 依次输出数组的值 索引为0的赋值了输出地址，其他没赋值输出null</span><br><span class="line">        for (int i = 0; i &lt; merchandises.length; i++) &#123;</span><br><span class="line">            System.out.println(merchandises[i]);</span><br><span class="line">        &#125;</span><br><span class="line">        // 没赋值的引用，访问属性，也就是二级跳，会报空指针</span><br><span class="line">        System.out.println(merchandises[1].name);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="像自定义类型一样使用类"><a href="#像自定义类型一样使用类" class="headerlink" title="像自定义类型一样使用类"></a>像自定义类型一样使用类</h2><h3 id="类就是一种自定义类型"><a href="#类就是一种自定义类型" class="headerlink" title="类就是一种自定义类型"></a>类就是一种自定义类型</h3></li>
<li>在类定义中可以使用类，创建类的引用</li>
<li>在类定义中，甚至可以使用类自己的类创建引用</li>
<li>引用类型的缺省值是null。<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">public class Phone &#123;</span><br><span class="line">    double price;</span><br><span class="line">    boolean hasFigurePrintUnlocker;</span><br><span class="line"></span><br><span class="line">    Phone prePhone;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">public class MyPhoneMaker &#123;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        Phone phone = new Phone();</span><br><span class="line"></span><br><span class="line">        phone.hasFigurePrintUnlocker = true;</span><br><span class="line">        phone.price = 1999;</span><br><span class="line"></span><br><span class="line">        phone.prePhone = new Phone();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="Java中的包和访问修饰符"><a href="#Java中的包和访问修饰符" class="headerlink" title="Java中的包和访问修饰符"></a>Java中的包和访问修饰符</h2><h3 id="类太混乱？用package管理"><a href="#类太混乱？用package管理" class="headerlink" title="类太混乱？用package管理"></a>类太混乱？用package管理</h3><ul>
<li>package语句告诉Java这个类在哪个package里。package语句要和源文件的目录完全对应，大小写要一致</li>
<li>一般类都放在包里，不会直接放在根目录</li>
<li>不同的包里可以有相同的名字</li>
<li>一个类只能有一个package语句，必须在类的第一行</li>
</ul>
<h3 id="类使用频繁？用import"><a href="#类使用频繁？用import" class="headerlink" title="类使用频繁？用import"></a>类使用频繁？用import</h3><h3 id="访问修饰符"><a href="#访问修饰符" class="headerlink" title="访问修饰符"></a>访问修饰符</h3><ul>
<li>public：可以被任意包中的类访问</li>
<li>缺省：当前包可见</li>
<li>private: 当前类可见<ul>
<li>成员变量应该都声明为private</li>
<li>有些时候，会把所有的构造方法都定义成private的，然后使用静态方法调用构造方法</li>
</ul>
</li>
</ul>
<h3 id="类的全限定名"><a href="#类的全限定名" class="headerlink" title="类的全限定名"></a>类的全限定名</h3><ul>
<li>包名 + 类名 = 类的全限定名。或者叫类的全名</li>
<li>同一个Java程序中类的全名不可重复</li>
</ul>
<h1 id="调试程序"><a href="#调试程序" class="headerlink" title="调试程序"></a>调试程序</h1><h2 id="用断点调试程序"><a href="#用断点调试程序" class="headerlink" title="用断点调试程序"></a>用断点调试程序</h2><h3 id="程序调试标准动作"><a href="#程序调试标准动作" class="headerlink" title="程序调试标准动作"></a>程序调试标准动作</h3><ul>
<li>查看变量的值，展开实例看成员变量的值</li>
<li>Step Over：执行一行</li>
<li>Evaluate Expression：在对话框输入代码，直接执行看结果值</li>
<li>条件断点：给断点设置条件，只有满足条件时，程序才会在该断点停住（右击断点进行设置）</li>
</ul>
<h1 id="方法、返回值、参数"><a href="#方法、返回值、参数" class="headerlink" title="方法、返回值、参数"></a>方法、返回值、参数</h1><h2 id="方法"><a href="#方法" class="headerlink" title="方法"></a>方法</h2><p>方法中定义的变量为局部变量</p>
<h3 id="方法是什么"><a href="#方法是什么" class="headerlink" title="方法是什么"></a>方法是什么</h3><ul>
<li>类中如果不定义方法，只定义成员变量，那么一个类就没有了功能，只是简单的数据的封装。</li>
<li>类通过成员变量和方法描述世界。成员变量是描述一类事物的属性，是数据；方法是描述一<br>类事物的行为和功能，是对数据的操作。</li>
<li>方法是 Java 中代码执行的单元，是代码的载体.所有的代码，都必须属于某一个方法</li>
<li>方法不是对象的一部分，它是类的一部分。每个对象可以给成员变量赋不同的值，但是无法<br>让方法有不同的行为。同理，无论在一个类中定义多少方法，都不会让影响创建一个对象所<br>占用的内存<h3 id="方法的特殊之处"><a href="#方法的特殊之处" class="headerlink" title="方法的特殊之处"></a>方法的特殊之处</h3></li>
<li>与代码块相比<ul>
<li>有名字</li>
<li>有返回值</li>
<li>有参数</li>
<li>有this自引用</li>
<li>明确属于某一个类</li>
<li>通过对象引用来调用<h2 id="返回值"><a href="#返回值" class="headerlink" title="返回值"></a>返回值</h2></li>
</ul>
</li>
<li>在方法定义中指定方法的返回值类型</li>
<li>Java中一个方法只能有一种返回值，如果不需要返回值则用void表示</li>
<li>如果定义了返回值，则必须使用 return 语句返回方法的返回值，return 是 Java 的关键字</li>
<li>可以认为，返回值必须要能够用来给返回值类型的变量赋值</li>
<li>返回值如果是基本类型，则要类型完全相同，或者符合类型自动转换规则，若不符合，可以使用强制转换<h2 id="参数"><a href="#参数" class="headerlink" title="参数"></a>参数</h2></li>
<li>参数是定义在方法名字后面的括号里的</li>
<li>参数定义的规范和变量一样，都是类型名字加标识符，这里的标识符我们叫做参数名。</li>
<li>方法体中的代码可以使用参数</li>
<li>参数的值在调用方法的时候需要给出，有的资料叫做实参（实际参数）</li>
<li>对应的，方法定义这里的参数，叫做形参（形式参数）<h2 id="参数和返回值如何传递"><a href="#参数和返回值如何传递" class="headerlink" title="参数和返回值如何传递"></a>参数和返回值如何传递</h2></li>
<li>方法执行完毕，参数和方法的局部变量的数据就会被删除回收。就好像草纸，作用是计算一个值，算好之后，草纸就可以扔了</li>
<li>方法里的代码并不能改变实参的值。</li>
<li>方法里使用的参数相当于一个局部变量。使用方法前，会用实参给局部变量赋值。</li>
<li>可以把有返回值的方法，当成一个成员变量，当成一个类型为返回值类型的成员变量<h2 id="参数、局部变量、实例的地盘"><a href="#参数、局部变量、实例的地盘" class="headerlink" title="参数、局部变量、实例的地盘"></a>参数、局部变量、实例的地盘</h2></li>
<li>参数和局部变量都是演草纸，方法执行完就清除了</li>
<li>对象是实体/实例，不是变量。对象创建出来后，被堆在一起，放在类似<br>公告板的地方。方法里创建的对象是不会随着方法结束被清除的。所以对<br>象的地盘不受限制，只要有引用指向一个对象，这个对象的数据就可以通<br>过这个引用来访问  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">public class Animal &#123;</span><br><span class="line">    String name = &quot;小红&quot;;</span><br><span class="line"></span><br><span class="line">    public void describe()&#123;</span><br><span class="line">        System.out.println(&quot;动物的名字：&quot; + name);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void changeName(Animal a)&#123;</span><br><span class="line">        a.name = name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args)&#123;</span><br><span class="line">        Animal a1 = new Animal();</span><br><span class="line">        Animal a2 = new Animal();</span><br><span class="line">        a1.name = &quot;小明&quot;;</span><br><span class="line"></span><br><span class="line">        a1.describe(); // 动物的名字：小明</span><br><span class="line">        a2.describe(); // 动物的名字：小红</span><br><span class="line">        a1.changeName(a2);</span><br><span class="line">        a2.describe(); // 动物的名字：小明</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="this"><a href="#this" class="headerlink" title="this"></a>this</h2></li>
<li>访问局部变量的完整形态，”this.成员变量的名字”</li>
<li>方法里隐藏着一个this自引用，指向调用这个方法的对象。</li>
<li>使用一个对象调用方法，也叫做在这个对象上调用方法。因为方法可以访问这个对象的值<img src="/blog/2022/07/15/Java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/pic-1.png" class="" title="deploy">  </li>
</ul>
<h1 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h1><h2 id="多行注释"><a href="#多行注释" class="headerlink" title="多行注释"></a>多行注释</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">/*</span><br><span class="line"></span><br><span class="line">这是一个多行注释</span><br><span class="line"> */</span><br></pre></td></tr></table></figure>
<h2 id="给类添加注释（Javadoc）"><a href="#给类添加注释（Javadoc）" class="headerlink" title="给类添加注释（Javadoc）"></a>给类添加注释（Javadoc）</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> *</span><br><span class="line"> * 对这个类的说明</span><br><span class="line"> *</span><br><span class="line"> * @author 作者</span><br><span class="line"> *</span><br><span class="line"> */</span><br></pre></td></tr></table></figure>
<h2 id="给方法添加注释（Javadoc）"><a href="#给方法添加注释（Javadoc）" class="headerlink" title="给方法添加注释（Javadoc）"></a>给方法添加注释（Javadoc）</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 方法注释</span><br><span class="line"> * @param count 目标库存数</span><br><span class="line"> * @return 达到目标库存数，则为true，否则为false</span><br><span class="line"> */</span><br></pre></td></tr></table></figure>
<h1 id="封装"><a href="#封装" class="headerlink" title="封装"></a>封装</h1><h2 id="把操作成员变量的代码放在类里"><a href="#把操作成员变量的代码放在类里" class="headerlink" title="把操作成员变量的代码放在类里"></a>把操作成员变量的代码放在类里</h2><ul>
<li>初始化成员变量</li>
<li>访问和设置成员变量的值</li>
<li>用类定义成员变量，并把操作成员变量的代码都放在类里，就是封装<ul>
<li>可以集中管控，自己的成员变量别人不可以乱改，避免出现非法的状态，比如库存为负数</li>
<li>代码逻辑可以公用，避免代码重复，修改的时候只需改一处</li>
<li>封装的好，可以更好的抽象一类事物</li>
</ul>
</li>
</ul>
<h2 id="方法重载"><a href="#方法重载" class="headerlink" title="方法重载"></a>方法重载</h2><h3 id="方法签名"><a href="#方法签名" class="headerlink" title="方法签名"></a>方法签名</h3><ul>
<li>方法签名：方法名+依次参数类型。注意，返回值不属于方法签名。方法签<br>名是一个方法在一个类中的唯一标识</li>
<li>同一个类中方法可以重名，但是签名不可以重复。一个类中如果定义了名字<br>相同，签名不同的方法，就叫做方法的重载<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">public double buy() &#123; // buy()就是方法签名</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">public double buy(int count) &#123;  // buy() + int就是方法签名</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">public double buy(int count, boolean isVIP) &#123;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">public double buy(boolean isVIP, int count) &#123; // 注意类型顺序不同，签名也不一样</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="重载参数的匹配规则"><a href="#重载参数的匹配规则" class="headerlink" title="重载参数的匹配规则"></a>重载参数的匹配规则</h3>参数不必完全类型一样，对于数字类型的参数，实参数可以自动类型转换成形参类型即可<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">public double buy(double count) &#123;&#125;</span><br><span class="line">public double buy(int count) &#123;&#125;</span><br><span class="line"></span><br><span class="line">比如：</span><br><span class="line">实参为float count = 3; 调用的就是buy(double count)</span><br><span class="line">实参为byte count = 3; 调用的就是buy(int count)</span><br><span class="line">```  </span><br><span class="line">**特殊之处**  </span><br><span class="line">参数满足自动类型转换的方法有多个时，选择就近调用。比如上面的byte，可以转为int，也可以转为double，但调用了int</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 构造方法</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 构造方法是什么</span></span></span><br><span class="line">* 构造方法的方法名必须与类名一样，而且构造方法没有返回值。这样的方法才是构造方法。</span><br><span class="line">* 构造方法可以有参数，规则和语法于普通方法一样。使用时，参数传递给 new 语句后类名的括号后面。</span><br><span class="line">* 如果没有显示的添加一个构造方法，Java会给每个类都会默认自带一个无参数的构造方法。</span><br><span class="line">* 如果我们自己添加类构造方法，Java就不会再添加无参数的构造方法。这时候，就不能直接 new 一个对象不传递参数了 </span><br><span class="line">* 所以我们一直都在使用默认构造方法，这也是为什么创建对象的时候类名后面要有一个括号的原因。</span><br><span class="line">* 构造方法无法被点操作符调用或者在普通方法里调用，只能通过 new 语句在创建对象的时候，间接调用。</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 理解为啥构造方法没有返回值</span></span></span><br><span class="line">因为有返回值也没有意义，new 语句永远返回的是创建出来的对象的引用</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 构造方法重载与互相调用</span></span></span><br><span class="line">**注意：** 构造方法执行前，会执行给局部变量赋初始值的操作  </span><br><span class="line">所有的代码都必须在方法里，那给成员变量赋值的代码在哪个方法里呢？  </span><br><span class="line">```shell</span><br><span class="line">public class Demo&#123;</span><br><span class="line">  public int count = 999/0;</span><br><span class="line">  public static void main(String[] args)&#123;</span><br><span class="line">    Demo d = new Demo(); // 会报错，发现有一个&lt;init&gt;方法</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
原来构造方法在内部变成了<init>方法</li>
<li>构造方法的重载和普通方法一样</li>
<li>在构造方法里能调用重载的构造方法。语法为this(实参列表)</li>
<li>构造方法不能自己调用自己，这会是一个死循环</li>
<li>在调用重载的构造方法时，不可以使用成员变量。因为用语意上讲，这个对象还没有被初始化完成，处于中间状态</li>
<li>在构造方法里才能调用重载的构造方法时，必须是方法的第一行。后面可以继续有代码</li>
</ul>
<h2 id="静态变量"><a href="#静态变量" class="headerlink" title="静态变量"></a>静态变量</h2><ul>
<li>静态变量使用 static 修饰符 </li>
<li>静态变量如果不赋值，Java也会给它赋以其类型的初始值 </li>
<li>静态变量一般使用全大写字母加下划线分割。这是一个习惯用法 </li>
<li>所有的代码都可以使用静态变量，只要根据防范控制符的规范，这个静态变量对其可见即可  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 比如 public 的静态变量，所有的代码都可以使用它</span><br><span class="line">public static double DISCOUNT_FOR_VIP = 0.95;</span><br><span class="line"></span><br><span class="line">// 但是如果没有public修饰符，只能当前包的代码能使用它</span><br><span class="line">static int STATIC_VARIABLE_CURR_PACKAGE_ONLY = 100;</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="静态方法"><a href="#静态方法" class="headerlink" title="静态方法"></a>静态方法</h2><ul>
<li>静态方法使用 static 修饰符</li>
<li>静态方法的方法名没有约定俗称全大写</li>
<li>静态方法可以访问静态变量，包括自己类的静态变量和在访问控制符允许的别的类的静态变量</li>
<li>静态方法没有this自引用，它不属于某个实例，调用的时候也无需引用，直接用类名调用，所以它也不能直接访问成员变量</li>
<li>然在静态方法里面，也可以自己创建对象，或者通过参数，获得对象的引用，进而调用方法和访问成员变量</li>
<li>静态方法只是没有this自引用的方法而已<h3 id="静态方法的重载"><a href="#静态方法的重载" class="headerlink" title="静态方法的重载"></a>静态方法的重载</h3>和成员方法一样</li>
</ul>
<h2 id="static代码块和static变量初始化"><a href="#static代码块和static变量初始化" class="headerlink" title="static代码块和static变量初始化"></a>static代码块和static变量初始化</h2><ul>
<li>使用某个静态变量的代码块必须在静态变量后面（如果只是赋值没有限制）<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">public class Demo &#123;</span><br><span class="line">  public static double SVIP_DISCOUNT;</span><br><span class="line">  static &#123;</span><br><span class="line">        SVIP_DISCOUNT = 0.75;</span><br><span class="line">        System.out.println(&quot;静态代码块1里的SVIP_DISCOUNT&quot; + SVIP_DISCOUNT);</span><br><span class="line"></span><br><span class="line">        // 这段代码在哪个方法中呢？&lt;clinit&gt;，即class init。会在每个class初始化的时候被调用一次</span><br><span class="line">        // SVIP_DISCOUNT = 9/0;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">public class Demo &#123;</span><br><span class="line">  static &#123;</span><br><span class="line">        SVIP_DISCOUNT = 0.75; // 只赋值没有调用，所以静态变量的声明放静态代码块后面不会报错</span><br><span class="line">    &#125;</span><br><span class="line">  public static double SVIP_DISCOUNT;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">* static代码块可以有多个，是从上向下顺序执行的</span><br><span class="line">```shell</span><br><span class="line">public class Demo &#123;</span><br><span class="line">  public static double SVIP_DISCOUNT;</span><br><span class="line">  static &#123;</span><br><span class="line">        SVIP_DISCOUNT = 0.75;</span><br><span class="line">  &#125;</span><br><span class="line">  static &#123;</span><br><span class="line">        SVIP_DISCOUNT = 0.1; // 最终SVIP_DISCOUNT的值为0.1</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">* 静态代码块在类从磁盘加载到java进程时，就会初始化好</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Math和Scanner</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">String</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 特点</span></span></span><br><span class="line">不可变。String用来存储字符的数据是 private 的，而且不提供任何修改</span><br><span class="line">内容的方法，所以String 对象一旦生成，其内容就是完全不可能被修改的</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">main方法和System类</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># main方法</span></span></span><br><span class="line">* main 方法是一个静态的，有 String[] 做参数的，没有返回值的方法而已。它的特殊性在于 Java 可以把 main 方作为程序入口</span><br><span class="line">* 调用main方法</span><br><span class="line">```shell</span><br><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        System.out.println(&quot;进入了Demo的main方法&quot;);</span><br><span class="line">        LearnMain.main(args); // 其它类的main方法</span><br><span class="line">        System.out.println(&quot;Demo的main方法执行结束&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="System类"><a href="#System类" class="headerlink" title="System类"></a>System类</h2></li>
</ul>
<h1 id="StringBuilder"><a href="#StringBuilder" class="headerlink" title="StringBuilder"></a>StringBuilder</h1><h2 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h2><p>StringBuilder是一个非常方便的用来拼接和处理字符串的类， 和String不同的是，它是可变的</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        // TODO StringBuilder首先是可变的</span><br><span class="line">        // TODO 而且对它进行操作的方法，都会返回this自引用。这样我们就可以一直点下去，对String进行构造。</span><br><span class="line">        StringBuilder strBuilder = new StringBuilder();</span><br><span class="line"></span><br><span class="line">        long longVal = 123456789;</span><br><span class="line"></span><br><span class="line">        strBuilder.append(true).append(&quot;abc&quot;).append(longVal);</span><br><span class="line"></span><br><span class="line">        System.out.println(strBuilder.toString());</span><br><span class="line">        System.out.println(strBuilder.reverse().toString());</span><br><span class="line">        System.out.println(strBuilder.reverse().toString());</span><br><span class="line">        System.out.println(strBuilder.toString());</span><br><span class="line"></span><br><span class="line">        System.out.println(strBuilder.delete(0, 4).toString());</span><br><span class="line"></span><br><span class="line">        System.out.println(strBuilder.insert(3,&quot;LLLLL&quot;).toString());</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="继承与组合"><a href="#继承与组合" class="headerlink" title="继承与组合"></a>继承与组合</h1><h2 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h2><h3 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h3><ul>
<li>继承的语法就是在类名后面使用extends 加要继承的类名</li>
<li>被继承的类叫做父类（Parent Class），继承者叫做子类（Sub Class）</li>
<li>Java中只允许一个类有一个直接的父类（Parent Class），即所谓的单继承</li>
<li>子类继承了父类什么呢？所有的属性和方法，但不能访问父类的private的成员<h3 id="重写（覆盖）"><a href="#重写（覆盖）" class="headerlink" title="重写（覆盖）"></a>重写（覆盖）</h3>继承的核心意义，就是让子类可以覆盖掉父类的方法  <h4 id="规则"><a href="#规则" class="headerlink" title="规则"></a>规则</h4></li>
<li>参数列表与被重写方法的参数列表必须完全相同。符合自动类型转换也不行。</li>
<li>返回类型与被重写方法的返回类型可以不相同，但是必须是父类返回值的派生类（java5 及更早版本返回类型要一样，java7 及更高版本可以不同</li>
<li>访问权限不能比父类中被重写的方法的访问权限更低。例如：如果父类的一个方法被声明为 public，那么在子类中重写该方法就不能声明为 protected</li>
<li>父类的成员方法只能被它的子类重写</li>
<li>声明为 final 的方法不能被重写</li>
<li>声明为 static 的方法不能被重写，但是能够被再次声明</li>
<li>子类和父类在同一个包中，那么子类可以重写父类所有方法，除了声明为 private 和 final 的方法</li>
<li>子类和父类不在同一个包中，那么子类只能够重写父类的声明为 public 和 protected 的非 final 方法</li>
<li>重写的方法能够抛出任何非强制异常，无论被重写的方法是否抛出异常。但是，重写的方法不能抛出新的强制性异常，或者比被重写方法声明的更广泛的强制性异常，反之则可以</li>
<li>构造方法不能被重写<h4 id="运行原理"><a href="#运行原理" class="headerlink" title="运行原理"></a>运行原理</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">class Animal&#123;</span><br><span class="line">    public void move()&#123;</span><br><span class="line">        System.out.println(&quot;动物可以移动&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class Dog extends Animal&#123;</span><br><span class="line">    public void move()&#123;</span><br><span class="line">        System.out.println(&quot;狗可以跑和走&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">    public void sleep()&#123;</span><br><span class="line">        System.out.println(&quot;狗可以睡觉&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String args[])&#123;</span><br><span class="line">        Animal a = new Animal(); // Animal 对象</span><br><span class="line">        Animal b = new Dog(); // Dog 对象</span><br><span class="line"></span><br><span class="line">        a.move();// 执行 Animal 类的方法</span><br><span class="line">        b.move();//执行 Dog 类的方法</span><br><span class="line">        b.sleep();// 编译报错，因为b的引用类型Animal没有sleep方法</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">尽管 b 属于 Animal 类型引用，但是它运行的是 Dog 类的 move方法。  </span><br><span class="line">由于编译阶段，只检查参数的引用类型。运行时，JVM指定对象的类型并运行该对象的方法。</span><br><span class="line">之所以能编译成功，是因为 Animal 类中存在 move 方法，然而运行时，运行的是特定对象的方法  </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># super</span></span></span><br><span class="line">* super是子类和父类交流的桥梁，但是并不是父类的引用</span><br><span class="line">* super和this自引用不一样。this可以直接输出，super不可以，只能super.来访问父类属性和方法</span><br><span class="line">* 使用super可以调用父类的方法和属性（当然必须满足访问控制符的控制）</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## super：调用父类的构造方法</span></span></span><br><span class="line">* 使用super调用父类的构造方法，必须是子类构造方法的第一个语句</span><br><span class="line">* super调用构造方法，不可以使用super访问父类的属性和方法</span><br><span class="line">* 子类构造方法会默认调用super()父类的无参构造方法，如果父类无参构造方法没有了，子类就需要super调用有参构造方法</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 组合</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 子类对象里藏着父类对象</span></span></span><br><span class="line">子类对象中有父类对象的引用  </span><br><span class="line">```shell</span><br><span class="line">public class Phone &#123;</span><br><span class="line">    private String name;</span><br><span class="line">    // 这种在自己的类里，使用别的类的两类之间关系，我们叫做&quot;has-a&quot;，也称为组合</span><br><span class="line">    // 在我们用类构造的世界中，&quot;Phone中有一个商品，但是Phone本身不是商品（划重点！）&quot;</span><br><span class="line">    private MerchandiseV2 merchandise;</span><br><span class="line"></span><br><span class="line">    public PhoneHasAMerchandise(String name) &#123;</span><br><span class="line">        this.name = name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void describePhone() &#123;</span><br><span class="line">        System.out.println(&quot;此手机商品属性如下&quot;);</span><br><span class="line">        merchandise.describe();</span><br><span class="line">        System.out.println(&quot;手机名字为&quot; + name);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="继承与组合如何理解"><a href="#继承与组合如何理解" class="headerlink" title="继承与组合如何理解"></a>继承与组合如何理解</h2><ul>
<li>继承，表达的是一种”is-a”的关系，也就是说，在你用类构造的世界中，”子类是父类的一种特殊类别”</li>
<li>组合，表达的是一种”has-a”的关系。<br>灵魂拷问：”XX到底是YY的一种，还是只是组合了YY？”</li>
</ul>
<h2 id="父类和子类的引用赋值关系"><a href="#父类和子类的引用赋值关系" class="headerlink" title="父类和子类的引用赋值关系"></a>父类和子类的引用赋值关系</h2><ul>
<li>父类引用可以指向子类对象，子类引用不可以指向父类的对象</li>
<li>可以进行强制类型转换，如果类型不对，会出错</li>
<li>可以调用的方法，是受引用类型决定的（虽然父类引用可以指向子类对象，但如果父类没有子类A方法，调用子类A方法会报错）</li>
</ul>
<h1 id="多态"><a href="#多态" class="headerlink" title="多态"></a>多态</h1><h2 id="到底调用的哪个方法？"><a href="#到底调用的哪个方法？" class="headerlink" title="到底调用的哪个方法？"></a>到底调用的哪个方法？</h2><h3 id="可以调用哪些方法，取决于引用类型。"><a href="#可以调用哪些方法，取决于引用类型。" class="headerlink" title="可以调用哪些方法，取决于引用类型。"></a>可以调用哪些方法，取决于引用类型。</h3><ul>
<li>无论一个方法是使用哪个引用被调用的，”它都是在实际的对象上执行的”。执行的任何一个方法，都是这个对象所属的类的方法。<br>如果没有，就去父类找，再没有，就去父类的父类找，依次寻找，直到找到。<h3 id="重写-覆盖-是多态里最重要的一种形式"><a href="#重写-覆盖-是多态里最重要的一种形式" class="headerlink" title="重写(覆盖)是多态里最重要的一种形式"></a>重写(覆盖)是多态里最重要的一种形式</h3><h3 id="this自引用的角度，理解覆盖"><a href="#this自引用的角度，理解覆盖" class="headerlink" title="this自引用的角度，理解覆盖"></a>this自引用的角度，理解覆盖</h3>我们一直说子类里又一个（特殊的）父类的对象。这时候，这个特殊的父类的对象里的this自引用，是子类的引用。<br>那么自然的，即使是在继承自父类的代码里，去调用一个方法，也是先从子类开始，一层层继承关系的找。<br>这也是Java选择单继承的重要原因之一。在多继承的情况下，如果使用不当，多态可能会非常复杂，以至于使用的代价超过其带来的好处。  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">class Animal&#123;</span><br><span class="line">    public Animal(String name)&#123;</span><br><span class="line">        System.out.println(&quot;父类&quot;);</span><br><span class="line">        System.out.println(this); // com.geekbang.supermarket.Dog@1540e19d</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class Dog extends Animal&#123;</span><br><span class="line">    public Dog(String name)&#123;</span><br><span class="line">        super(name);</span><br><span class="line">        System.out.println(&quot;子类&quot;);</span><br><span class="line">        System.out.println(this); // com.geekbang.supermarket.Dog@1540e19d</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String args[])&#123;</span><br><span class="line">        Dog b = new Dog(&quot;222&quot;); // Dog 对象</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="强制类型转换"><a href="#强制类型转换" class="headerlink" title="强制类型转换"></a>强制类型转换</h2>强制类型转换的前提是父类引用指向的对象的类型是子类的时候才可以进行强制类型转换，<br>如果父类引用指向的对象的类型不是子类的时候将产生java.lang.ClassCastException异常(类型强制转换异常)  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">class Animal&#123;</span><br><span class="line">    public Animal(String name)&#123;</span><br><span class="line">        System.out.println(&quot;父类&quot;);</span><br><span class="line">        System.out.println(this);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class Dog extends Animal&#123;</span><br><span class="line">    public Dog(String name)&#123;</span><br><span class="line">        super(name);</span><br><span class="line">        System.out.println(&quot;子类&quot;);</span><br><span class="line">        System.out.println(this);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">public class Demo &#123;</span><br><span class="line">    public static void main(String args[])&#123;</span><br><span class="line">        Animal a = new Dog(&quot;222&quot;); // Dog 对象</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">       Animal a = new Animal(<span class="string">&quot;222&quot;</span>); // Animal 对象 指向父类对象，执行下面强制转换时，会类型转换异常</span></span><br><span class="line">        Dog d = (Dog) a;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="多态里的更多语法点"><a href="#多态里的更多语法点" class="headerlink" title="多态里的更多语法点"></a>多态里的更多语法点</h2><h3 id="静态多态：重载"><a href="#静态多态：重载" class="headerlink" title="静态多态：重载"></a>静态多态：重载</h3><ul>
<li>重载调用哪个方法，和参数的引用类型相关，和引用实际指向的类型无关</li>
<li>如果参数引用类型没有完全匹配的，则会根据继承关系，沿着参数当前类型，向下撸<h3 id="动态多态：重写（覆盖）"><a href="#动态多态：重写（覆盖）" class="headerlink" title="动态多态：重写（覆盖）"></a>动态多态：重写（覆盖）</h3><h3 id="多态核心问题"><a href="#多态核心问题" class="headerlink" title="多态核心问题"></a>多态核心问题</h3>要调用哪个类的<br>哪个方法，这个方法用到的数据（this 引用）是谁</li>
</ul>
<h1 id="instanceof-操作符"><a href="#instanceof-操作符" class="headerlink" title="instanceof 操作符"></a>instanceof 操作符</h1><p>可以判断一个引用指向的对象是否是某一个类型或者其子类,如果引用是null，则肯定返回false</p>
<h1 id="继承专属的访问控制：protected"><a href="#继承专属的访问控制：protected" class="headerlink" title="继承专属的访问控制：protected"></a>继承专属的访问控制：protected</h1><ul>
<li>protected 可见性 = default可见范围 + 对子类可见(即使子类和父类不再一个包)</li>
<li>子类重写父类方法时，可见性不能更低，但是可以用更高的修饰符，为什么呢？<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">父类引用可以指向子类对象，此时就要调用子类重写父类的方法</span><br><span class="line">如果重写父类的方法可见性更低，就无法调用，违背了多态的核心思想</span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th>修饰符</th>
<th>当前类</th>
<th>同一包内</th>
<th>子孙类（同一包）</th>
<th>子孙类（不同包）</th>
<th>其他包</th>
</tr>
</thead>
<tbody><tr>
<td>private</td>
<td>Y</td>
<td>N</td>
<td>N</td>
<td>N</td>
<td>N</td>
</tr>
<tr>
<td>default</td>
<td>Y</td>
<td>Y</td>
<td>Y</td>
<td>N</td>
<td>N</td>
</tr>
<tr>
<td>protected</td>
<td>Y</td>
<td>Y</td>
<td>Y</td>
<td>Y/N</td>
<td>N</td>
</tr>
<tr>
<td>public</td>
<td>Y</td>
<td>Y</td>
<td>Y</td>
<td>Y</td>
<td>Y</td>
</tr>
</tbody></table>
</li>
<li><em>说明</em>*  </li>
<li>子类与基类在同一包中：被声明为 protected 的变量、方法和构造器能被同一个包中的任何其他类访问；</li>
<li>子类与基类不在同一包中：那么在子类中，子类实例可以访问其从基类继承而来的 protected 方法，而不能访问基类实例的protected方法。</li>
</ul>
<h1 id="final-修饰符"><a href="#final-修饰符" class="headerlink" title="final 修饰符"></a>final 修饰符</h1><ul>
<li>final 修饰类：不可被继承</li>
<li>final 修饰方法：不可被子类覆盖</li>
<li>final 修饰变量：不可被重新赋值，必须显式指定初始值。通常和 static 修饰符一起使用来创建类常量。</li>
</ul>
<h1 id="万类之祖：Object类"><a href="#万类之祖：Object类" class="headerlink" title="万类之祖：Object类"></a>万类之祖：Object类</h1><p>所有的类，都间接或者直接的继承自 Object 类</p>
<h2 id="Object-类中的方法"><a href="#Object-类中的方法" class="headerlink" title="Object 类中的方法"></a>Object 类中的方法</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String args[])&#123;</span><br><span class="line">        Object obj = new Object();</span><br><span class="line">        printObj(obj);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">private static void printObj(Object obj) &#123;</span><br><span class="line">    System.out.println(&quot;-----&quot; + obj + &quot;的详细内容-----&quot;);</span><br><span class="line">    System.out.println(obj); // java.lang.Object@1540e19d</span><br><span class="line">    System.out.println(obj.toString()); // java.lang.Object@1540e19d</span><br><span class="line">    System.out.println(obj.getClass()); // class java.lang.Object</span><br><span class="line">    System.out.println(obj.hashCode()); // 356573597</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="Object-类引用"><a href="#Object-类引用" class="headerlink" title="Object 类引用"></a>Object 类引用</h2><p>Object 类引用可以指向任何子类对象</p>
<h1 id="hashCode-和-equals-方法"><a href="#hashCode-和-equals-方法" class="headerlink" title="hashCode 和 equals 方法"></a>hashCode 和 equals 方法</h1><h2 id="hashCode-和-equals-方法初探"><a href="#hashCode-和-equals-方法初探" class="headerlink" title="hashCode 和 equals 方法初探"></a>hashCode 和 equals 方法初探</h2><ul>
<li>hashCode 可以翻译为哈希码，或者散列码。应该是一个表示对象的特征值的 int 整数</li>
<li>equals 方法应该用来判断两个对象从逻辑上是否相等<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Object obj1 = new Object();</span><br><span class="line">Object obj2 = new Object();</span><br><span class="line">Object obj3 = obj1;</span><br><span class="line">System.out.println(obj1 == obj2); // false</span><br><span class="line">System.out.println(obj1.equals(obj2)); // false</span><br><span class="line">System.out.println(obj1 == obj3); // true</span><br><span class="line"></span><br><span class="line">源码：</span><br><span class="line">public boolean equals(Object obj) &#123;</span><br><span class="line">        return (this == obj);</span><br><span class="line">&#125;</span><br><span class="line">从源码可以看出，比较的是对象是否相同，此时equals和==效果相同</span><br></pre></td></tr></table></figure>
<h2 id="String-类的-equals-方法"><a href="#String-类的-equals-方法" class="headerlink" title="String 类的 equals 方法"></a>String 类的 equals 方法</h2>上面说==比较的两个对象，那看看下面的代码  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">String s1 = &quot;abc&quot;;</span><br><span class="line">String s2 = &quot;abc&quot;;</span><br><span class="line">System.out.println(s1 == s2); // true</span><br></pre></td></tr></table></figure>
输出true，为啥呢，从代码结构看s1和s2是两个对象，其实Java对String的的优化<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">这两个字符串都在字符串常量池中，只创建了一次，只保存了一个&quot;abc&quot;。因此其内存地址相同，其结果为true。</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">String str1 = &quot;abc&quot;; // 在常量池中创建</span><br><span class="line">String str2 = new String(&quot;abc&quot;); // 在堆中创建</span><br><span class="line">System.out.print(str1==str2); // false</span><br><span class="line">System.out.println(str1.equals(str2)); // true</span><br></pre></td></tr></table></figure>
<h3 id="String中-和-equals-的区别是什么？"><a href="#String中-和-equals-的区别是什么？" class="headerlink" title="String中 == 和 equals 的区别是什么？"></a>String中 == 和 equals 的区别是什么？</h3></li>
<li>==<ul>
<li>对于基本类型，== 比较的是：值是否相同。</li>
<li>对于引用类型，== 比较的是：引用是否相同。（即判断两个对象的地址是否相同）</li>
</ul>
</li>
<li>equals<ul>
<li>值是否相同</li>
</ul>
</li>
</ul>
<h1 id="反射"><a href="#反射" class="headerlink" title="反射"></a>反射</h1><p>最后看</p>
<h1 id="面向对象三要素：封装、继承和多态"><a href="#面向对象三要素：封装、继承和多态" class="headerlink" title="面向对象三要素：封装、继承和多态"></a>面向对象三要素：封装、继承和多态</h1><h2 id="封装解决了什么问题，带来了什么问题"><a href="#封装解决了什么问题，带来了什么问题" class="headerlink" title="封装解决了什么问题，带来了什么问题"></a>封装解决了什么问题，带来了什么问题</h2><h2 id="继承解决了什么问题，带来了什么问题"><a href="#继承解决了什么问题，带来了什么问题" class="headerlink" title="继承解决了什么问题，带来了什么问题"></a>继承解决了什么问题，带来了什么问题</h2><h2 id="多态解决了什么问题，带来了什么问题"><a href="#多态解决了什么问题，带来了什么问题" class="headerlink" title="多态解决了什么问题，带来了什么问题"></a>多态解决了什么问题，带来了什么问题</h2><h1 id="枚举"><a href="#枚举" class="headerlink" title="枚举"></a>枚举</h1><p>枚举是一个特殊的类，一般表示一组常量</p>
<h2 id="声明"><a href="#声明" class="headerlink" title="声明"></a>声明</h2><ul>
<li>使用enum而非class声明  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">public enum Color &#123; </span><br><span class="line">    RED, </span><br><span class="line">    GREEN, </span><br><span class="line">    BLUE; </span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure></li>
<li>可以有属性、方法</li>
<li>构造方法必须是private的，不写也是private的  </li>
<li>内部类中使用  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">public class Test</span><br><span class="line">&#123;</span><br><span class="line">    enum Color</span><br><span class="line">    &#123;</span><br><span class="line">        RED, GREEN, BLUE;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">* 每个枚举都是通过 Class 在内部实现的，且所有的枚举值都是 public static final 的。  </span><br><span class="line">以上的枚举类 Color 转化在内部类实现：  </span><br><span class="line">```shell</span><br><span class="line">class Color</span><br><span class="line">&#123;</span><br><span class="line">     public static final Color RED = new Color();</span><br><span class="line">     public static final Color BLUE = new Color();</span><br><span class="line">     public static final Color GREEN = new Color();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="接口"><a href="#接口" class="headerlink" title="接口"></a>接口</h1><p>在JAVA编程语言中是一个抽象类型，是抽象方法的集合</p>
<h2 id="接口与类"><a href="#接口与类" class="headerlink" title="接口与类"></a>接口与类</h2><p>接口并不是类，编写接口的方式和类很相似  </p>
<ul>
<li>相似点<ul>
<li>可以有很多方法</li>
<li>接口文件保存在.java文件中，文件名使用接口名</li>
<li>接口的字节码文件保存在 .class 结尾的文件中</li>
</ul>
</li>
<li>区别<ul>
<li>接口不能用于实例化对象</li>
<li>接口没有构造方法</li>
<li>接口中所有的方法必须是抽象方法</li>
<li>接口不能包含成员变量，除了 static 和 final 变量</li>
<li>接口不是被类继承了，而是要被类实现</li>
<li>接口支持多继承<h2 id="接口特性"><a href="#接口特性" class="headerlink" title="接口特性"></a>接口特性</h2></li>
</ul>
</li>
<li>接口中的方法会被隐式的指定为 public abstract（只能是 public abstract，其他修饰符都会报错）</li>
<li>接口中可以含有变量，但是接口中的变量会被隐式的指定为 public static final 变量（并且只能是 public，用 private 修饰会报编译错误）</li>
<li>接口中的方法是不能在接口中实现的，只能由实现接口的类来实现接口中的方法<h2 id="声明-1"><a href="#声明-1" class="headerlink" title="声明"></a>声明</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">public interface InterfaceDemo &#123;</span><br><span class="line">    int Age = 11;</span><br><span class="line">    void run();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="接口实现"><a href="#接口实现" class="headerlink" title="接口实现"></a>接口实现</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">public class DemoInter implements InterfaceDemo&#123;</span><br><span class="line">    @Override</span><br><span class="line">    public void run() &#123;</span><br><span class="line">        int age = InterfaceDemo.Age;</span><br><span class="line">        System.out.println(&quot;&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="抽象类"><a href="#抽象类" class="headerlink" title="抽象类"></a>抽象类</h1><p>在面向对象的概念中，所有的对象都是通过类来描绘的，但是反过来，并不是所有的类都是用来描绘对象的，如果一个类中没有包含足够的信息来描绘一个具体的对象，这样的类就是抽象类</p>
<h2 id="抽象类特别之处"><a href="#抽象类特别之处" class="headerlink" title="抽象类特别之处"></a>抽象类特别之处</h2><p>不能实例化对象。<br>由于抽象类不能实例化对象，所以抽象类必须被继承，才能被使用</p>
<h2 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">public abstract class Demo&#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="抽象方法"><a href="#抽象方法" class="headerlink" title="抽象方法"></a>抽象方法</h2><p>Abstract 关键字同样可以用来声明抽象方法，抽象方法只包含一个方法名，而没有方法体</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">public abstract void sleep();</span><br><span class="line">```  </span><br><span class="line">* 一个类包含抽象方法，那么该类必须是抽象类</span><br><span class="line">* 任何子类必须重写父类的抽象方法，或者声明自身为抽象类</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># 抽象类与接口区别</span></span></span><br><span class="line">* 抽象类中的方法可以有方法体，接口不行</span><br><span class="line">* 抽象类中的成员变量可以是各种类型的，而接口中的成员变量只能是 public static final 类型的</span><br><span class="line">* 抽象类是可以有静态代码块和静态方法，接口中不能含有</span><br><span class="line">* 一个类只能继承一个抽象类，而一个类却可以实现多个接口</span><br><span class="line">**注意**  </span><br><span class="line">JDK 1.8 以后，接口允许包含具体实现的方法，该方法称为&quot;默认方法&quot;，默认方法使用 default 关键字修饰  </span><br><span class="line">```shell</span><br><span class="line">public interface Demo &#123;</span><br><span class="line">   default void print()&#123;</span><br><span class="line">      System.out.println(&quot;我是一辆车!&quot;);</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">静态默认方法  </span><br><span class="line">```shell</span><br><span class="line">public interface Demo &#123;</span><br><span class="line">   static void print()&#123;</span><br><span class="line">      System.out.println(&quot;我是一辆车!&quot;);</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="特殊类"><a href="#特殊类" class="headerlink" title="特殊类"></a>特殊类</h1><h2 id="枚举-1"><a href="#枚举-1" class="headerlink" title="枚举"></a>枚举</h2><h2 id="非公有类"><a href="#非公有类" class="headerlink" title="非公有类"></a>非公有类</h2><ul>
<li>最不特殊的类，可以认为就是被缺省访问控制符修饰的类。也就是说，和<br>public class 的区别仅仅是可以被访问的范围不一样</li>
<li>如果一个文件只有非公有类，那么类名和文件名可以不一样<h2 id="内部类"><a href="#内部类" class="headerlink" title="内部类"></a>内部类</h2></li>
<li>内部类的特殊之处在于可见性和可以访问的数据以及方法。内部类会被<br>认为是类本身的代码，所以外部类的 private 成员对其可见</li>
<li>内部类可以有父类，可以实现接口。<h3 id="静态内部类"><a href="#静态内部类" class="headerlink" title="静态内部类"></a>静态内部类</h3>可以有访问修饰符，可以在类外部访问（对比静态变量）<h3 id="成员内部类"><a href="#成员内部类" class="headerlink" title="成员内部类"></a>成员内部类</h3>可有访问修饰符，有外部类对象的 this 自引用（对比成员方法），可<br>以在外部使用，但是创建对象语法需要指明外部对象<h3 id="局部内部类"><a href="#局部内部类" class="headerlink" title="局部内部类"></a>局部内部类</h3>没有访问修饰符（对比局部变量） ，有外部类的引用，访问参数和<br>局部变量，必须是 final 的<h2 id="匿名类"><a href="#匿名类" class="headerlink" title="匿名类"></a>匿名类</h2></li>
<li>匿名类是一种创建接口和抽象类对象的语法，任何可以 new 一个对象的地方，<br>都可以使用匿名类</li>
<li>匿名类只能实现/继承一个接口/抽象类，本身没有名字</li>
<li>如果是在成员方法或者给成员方法赋值时创建匿名类，那么会有对外部对象<br>的this自引用</li>
<li>匿名类也可以访问外部类的 private 属性</li>
</ul>

        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="http://haohongbin.gitee.io/blog/page/2/index.html">http://haohongbin.gitee.io/blog/page/2/index.html</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="tag">学习总结</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
      
    </footer>
  </div>
</article>


  <article id="post-Java编程基础" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog/2022/07/14/Java%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80/">Java编程基础</a>
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2022-07-14T09:11:33.000Z" itemprop="datePublished">2022年07月14日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/blog/categories/Java/">Java</a>
  </div>

      
      
<a href="/blog/2022/07/14/Java%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80/#comments" class="article-comment-link">
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h1><p>类名、变量名以及方法名都被称为标识符。规则如下：  </p>
<ul>
<li>以字母（A-Z 或者 a-z）,美元符（$）、或者下划线（_）开始</li>
<li>首字符之后可以是字母（A-Z 或者 a-z）,美元符（$）、下划线（_）或数字的任何字符组合</li>
<li>大小写敏感</li>
<li>关键字不能用作标识符</li>
</ul>
<h1 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h1><p>每种基本数据类型都有相应的包装类：Byte、Short、Integer、Long、Float、Double、Character。<br>包装类提供了面向对象的实现，比如二进制位数（Integer.SIZE）、最小值（Integer.MIN_VALUE）、最大值（Integer.MAX_VALUE）等</p>
<h2 id="整数类型"><a href="#整数类型" class="headerlink" title="整数类型"></a>整数类型</h2><table>
<thead>
<tr>
<th>类型</th>
<th>字节</th>
<th>位数</th>
<th>值域</th>
<th>默认值</th>
</tr>
</thead>
<tbody><tr>
<td>int</td>
<td>4</td>
<td>32</td>
<td>-2,147,483,648（-2^31）~ 2,147,483,647（2^31-1）</td>
<td>0</td>
</tr>
<tr>
<td>short</td>
<td>2</td>
<td>16</td>
<td>-32768（-2^15）~ 32767（2^15-1）</td>
<td>0</td>
</tr>
<tr>
<td>long</td>
<td>8</td>
<td>64</td>
<td>-9,223,372,036,854,775,808（-2^63）~ 9,223,372,036,854,775,807（2^63-1）</td>
<td>0L</td>
</tr>
<tr>
<td>byte</td>
<td>1</td>
<td>8</td>
<td>-128（-2^7）~ 127（2^7-1）</td>
<td>0</td>
</tr>
</tbody></table>
<h2 id="浮点类型"><a href="#浮点类型" class="headerlink" title="浮点类型"></a>浮点类型</h2><table>
<thead>
<tr>
<th>类型</th>
<th>字节</th>
<th>位数</th>
<th>默认值</th>
<th>精度</th>
</tr>
</thead>
<tbody><tr>
<td>float</td>
<td>4</td>
<td>32</td>
<td>0.0f</td>
<td>单</td>
</tr>
<tr>
<td>double</td>
<td>8</td>
<td>64</td>
<td>0.0d</td>
<td>双（是float的2倍</td>
</tr>
</tbody></table>
<h2 id="布尔和字符类型"><a href="#布尔和字符类型" class="headerlink" title="布尔和字符类型"></a>布尔和字符类型</h2><table>
<thead>
<tr>
<th>类型</th>
<th>字节</th>
<th>位数</th>
<th>值域</th>
<th>默认值</th>
</tr>
</thead>
<tbody><tr>
<td>boolean</td>
<td>1</td>
<td>8</td>
<td>true,false</td>
<td>false</td>
</tr>
<tr>
<td>char</td>
<td>2</td>
<td>16</td>
<td>所有字符</td>
<td>u0000</td>
</tr>
</tbody></table>
<h2 id="字面量"><a href="#字面量" class="headerlink" title="字面量"></a>字面量</h2><p>7 是一个int字面量，而7.0是double字面量。  </p>
<h2 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h2><h3 id="自动类型转换"><a href="#自动类型转换" class="headerlink" title="自动类型转换"></a>自动类型转换</h3><p>不会出现问题的类型转换，编程语言可以做自动类型转换，低精度向高精度转换</p>
<ul>
<li>精度顺序：double&gt;float&gt;long&gt;int&gt;short&gt;byte</li>
<li>char可以转为int：</li>
<li>char不可以转为short：虽然都是两个byte，但char为无符号数，值域超出了short可以表示的范围<h3 id="强制类型转换"><a href="#强制类型转换" class="headerlink" title="强制类型转换"></a>强制类型转换</h3>可能出现问题的类型转换，需要使用强制类型转换，比如高精度向低精度转换   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">long a = 60; </span><br><span class="line">int b = 1; </span><br><span class="line">b = (int)a;</span><br><span class="line"></span><br><span class="line">int c = 65;</span><br><span class="line">char d = (char)c;</span><br></pre></td></tr></table></figure></li>
<li>会造成数据精度丢失  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">int a = 99;</span><br><span class="line">long b = 555555555555L;</span><br><span class="line">a = (int)b; // 此时a的值为1504774371</span><br></pre></td></tr></table></figure>
<h2 id="数值溢出"><a href="#数值溢出" class="headerlink" title="数值溢出"></a>数值溢出</h2></li>
<li>数值一旦计算溢出，结果将失去原有意义。比如两个正数会加出负数  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">int a = 2000000000;</span><br><span class="line">System.out.println(a+a); // 此时输出-294967296</span><br></pre></td></tr></table></figure></li>
<li><em>注意</em>* 实际上，JAVA中还存在另外一种基本类型 void，它也有对应的包装类 java.lang.Void，不过我们无法直接对它们进行操作</li>
</ul>
<h1 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h1><h2 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h2><p>+、-、*、/、%、++、–<br><strong>注意</strong><br>b = ++a 与 b = a++的区别，前者是先a+1再赋值给b，后者是先将a赋值给b,a再加1</p>
<h2 id="关系运算符"><a href="#关系运算符" class="headerlink" title="关系运算符"></a>关系运算符</h2><p>==、&gt;、&gt;=、&lt;、&lt;=、!=</p>
<h2 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h2><p>=、+=、-=、*=、/=、%=、&lt;&lt;=、&gt;&gt;=、&amp;=、|=、^=</p>
<h2 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</h2><p>&amp;、|、^、～、&lt;&lt;、&gt;&gt;、&gt;&gt;&gt;<br>1、&lt;&lt; 左移，右边补0。左移没有带符号位一说，因为符号位在最左侧<br>2、&gt;&gt; 符号位不动，其余位右移，符号位后边补0，又称带符号右移<br>3、&gt;&gt;&gt; 符号位一起右移，左边补0，又称无符号右移</p>
<p><strong>技巧</strong><br>(~x) = -(x + 1)  </p>
<ul>
<li>^    如果相对应位值相同，则结果为0，否则为1 <h2 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h2>&amp;&amp;、||、!<h2 id="条件运算符"><a href="#条件运算符" class="headerlink" title="条件运算符"></a>条件运算符</h2>条件运算符也被称为三元运算符。  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">public class Test &#123;</span><br><span class="line">   public static void main(String[] args)&#123;</span><br><span class="line">      int a , b;</span><br><span class="line">      a = 10;</span><br><span class="line">      // 如果 a 等于 1 成立，则设置 b 为 20，否则为 30</span><br><span class="line">      b = (a == 1) ? 20 : 30;</span><br><span class="line">      System.out.println( &quot;Value of b is : &quot; +  b );</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="instanceof-运算符"><a href="#instanceof-运算符" class="headerlink" title="instanceof 运算符"></a>instanceof 运算符</h2>该运算符用于操作对象实例，检查该对象是否是一个特定类型  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">String name = &quot;James&quot;;</span><br><span class="line">boolean result = name instanceof String; // 由于 name 是 String 类型，所以返回真</span><br></pre></td></tr></table></figure>
<h2 id="优先级"><a href="#优先级" class="headerlink" title="优先级"></a>优先级</h2>多用小括号把优先计算的表达式框起来</li>
</ul>
<h1 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h1><ul>
<li>什么是字符集（Charset）？<ul>
<li>字符集就是字符的集合。一般会包含一种语言的字符。比如GBK，是包含所有汉字字符的字符集。ASCII，是包含英文字符的字符集。</li>
<li>字符就是Java中的char,char就是character的简写</li>
</ul>
</li>
<li>什么是编码（Encoding）？<ul>
<li>char代表一个字符，char的本质也是数字。将数字映射到字符，就叫编码</li>
<li>将一个字符集映射到数字，就是给这个字符集编码。</li>
<li>有时间编码和字符集会混用</li>
</ul>
</li>
<li>常用的字符集<ul>
<li>ASCII码</li>
<li>Unicode,包含世界上所有常用字符。编码也有几种，UTF-8、UTF-16等</li>
<li>Unicode、GBK等常用的字符集都兼容ASCII</li>
</ul>
</li>
<li>Java中的字符集<ul>
<li>用UTF-16编码的Unicode</li>
<li>UTF-16用16个bit,即2个byte,这也是char占用2个byte的原因。</li>
</ul>
</li>
<li>转义符<ul>
<li>\n 换行</li>
<li>&quot; 双引号</li>
<li>\t 制表符</li>
<li>\uXXXX unicode编码对应的字符</li>
</ul>
</li>
</ul>
<h1 id="代码块和变量作用域"><a href="#代码块和变量作用域" class="headerlink" title="代码块和变量作用域"></a>代码块和变量作用域</h1><h2 id="大括号括起来的就是代码块"><a href="#大括号括起来的就是代码块" class="headerlink" title="大括号括起来的就是代码块"></a>大括号括起来的就是代码块</h2><ul>
<li>有名字的代码块 if-else代码块、for循环代码块、main方法代码块</li>
<li>代码块也叫体，比如for循环体、main方法体</li>
<li>代码块可以嵌套<h2 id="作用域和命名空间"><a href="#作用域和命名空间" class="headerlink" title="作用域和命名空间"></a>作用域和命名空间</h2></li>
</ul>
<h1 id="条件语句"><a href="#条件语句" class="headerlink" title="条件语句"></a>条件语句</h1><ul>
<li>if…else</li>
<li>switch case<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">switch(expression)&#123;</span><br><span class="line">    case value :</span><br><span class="line">       //语句</span><br><span class="line">       break; //可选</span><br><span class="line">    case value :</span><br><span class="line">       //语句</span><br><span class="line">       break; //可选</span><br><span class="line">    //你可以有任意数量的case语句</span><br><span class="line">    default : //可选</span><br><span class="line">       //语句</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">规则：  </span><br><span class="line">* switch 语句中的变量类型可以是： byte、short、int 或者 char。从 Java SE 7 开始，switch 支持字符串 String 类型了，同时 case 标签必须为字符串常量或字面量</span><br><span class="line">* case 语句中的值的数据类型必须与变量的数据类型相同，而且只能是常量或者字面常量</span><br><span class="line">* 当变量的值与 case 语句的值相等时，那么 case 语句之后的语句开始执行，直到 break 语句出现才会跳出 switch 语句</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">循环</span></span><br><span class="line">* for</span><br><span class="line">* while</span><br><span class="line">* do...while</span><br><span class="line">```shell</span><br><span class="line">do &#123;</span><br><span class="line">       //代码语句</span><br><span class="line">&#125;while(布尔表达式);</span><br></pre></td></tr></table></figure>
<h1 id="控制台输入"><a href="#控制台输入" class="headerlink" title="控制台输入"></a>控制台输入</h1></li>
<li>in.nextLine() 从命令行读取一行字符串</li>
<li>in.nextInt() 从命令行读取一个正整数<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Scanner in = new Scanner(System.in);</span><br><span class="line">System.out.println(&quot;请问你的名字是？&quot;);</span><br><span class="line">String str = in.nextLine();</span><br><span class="line">System.out.println(str + &quot;，你好。&quot;);</span><br><span class="line">System.out.println(&quot;请问你几岁了？&quot;);</span><br><span class="line">int age = in.nextInt();</span><br><span class="line">System.out.println(&quot;好的，&quot; + str + age + &quot;岁了。&quot;);</span><br></pre></td></tr></table></figure>
<h1 id="循环、判断实战"><a href="#循环、判断实战" class="headerlink" title="循环、判断实战"></a>循环、判断实战</h1></li>
<li>猜数字：生成一个指定范围内的随机正整数，从命令行读取一个整数，如果相同就猜中  </li>
<li>要求：  <ul>
<li>固定随机数的范围</li>
<li>支持猜测次数，指定次数内没猜对，就算失败</li>
<li>可以退出游戏</li>
<li>输出剩余的猜测次数</li>
<li>未猜中，提示猜测数目比实际数目小还是大</li>
<li>游戏结束后，输出猜数字游戏的统计</li>
<li>没有猜中，输出这次的目标数字</li>
<li>可以设置随机数的范围，可以设置最大猜测次数<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line">Scanner in = new Scanner(System.in);</span><br><span class="line">// 游戏设置</span><br><span class="line">int rangeStart = 1;</span><br><span class="line">int rangeEnd = 8;</span><br><span class="line">int guessTotal = 5;</span><br><span class="line">// 游戏统计</span><br><span class="line">int totalGameCount = 0;</span><br><span class="line">int totalCorrectCount = 0;</span><br><span class="line">// 是否结束游戏</span><br><span class="line">boolean stopGame = false;</span><br><span class="line">while (!stopGame)&#123;</span><br><span class="line">    // 初始化本次游戏的变量</span><br><span class="line">    int guessLeft = guessTotal;</span><br><span class="line">    int mod = rangeEnd - rangeStart;</span><br><span class="line">    double randNum = Math.random();</span><br><span class="line">    int num = ((int) (randNum * rangeEnd * 100)) % mod;</span><br><span class="line">    num += rangeStart;</span><br><span class="line">    if (num &lt;= rangeStart) &#123;</span><br><span class="line">        num = rangeStart + 1;</span><br><span class="line">    &#125;</span><br><span class="line">    if (num &gt;= rangeEnd) &#123;</span><br><span class="line">        num = rangeEnd - 1;</span><br><span class="line">    &#125;</span><br><span class="line">    System.out.println(&quot;=================== 猜 数 字 ===================&quot;);</span><br><span class="line">    System.out.println(&quot;目标数已经生成，数字在&quot; + rangeStart + &quot;到&quot; + rangeEnd + &quot;之间，&quot; +</span><br><span class="line">            &quot;不包括这两个数。共有&quot; + guessTotal + &quot;次猜测的机会。输入-1随时结束游戏。&quot;);</span><br><span class="line">    // 本次游戏是否开始了</span><br><span class="line">    boolean gameStart = true;</span><br><span class="line">    // 本次是否猜中数字</span><br><span class="line">    boolean guessCorrect = false;</span><br><span class="line">    while (guessLeft &gt; 0)&#123;</span><br><span class="line">        System.out.println(&quot;还有&quot; + guessLeft + &quot;次机会，请输入猜测的数字，回车确认&quot;);</span><br><span class="line">        int guessNum = in.nextInt();</span><br><span class="line">        // 输入-1，结束游戏</span><br><span class="line">        if (guessNum == -1) &#123;</span><br><span class="line">            stopGame = true;</span><br><span class="line">            break;</span><br><span class="line">        &#125;</span><br><span class="line">        if (guessNum &lt;= rangeStart || guessNum &gt;= rangeEnd) &#123;</span><br><span class="line">            System.out.println(&quot;请输入在&quot; + rangeStart + &quot;到&quot; + rangeEnd + &quot;之间，的数字，不包括这两个数。&quot;);</span><br><span class="line">            continue;</span><br><span class="line">        &#125;</span><br><span class="line">        // 只要至少猜过一次，就算玩过了。</span><br><span class="line">        if (gameStart) &#123;</span><br><span class="line">            totalGameCount++;</span><br><span class="line">            gameStart = false;</span><br><span class="line">        &#125;</span><br><span class="line">        // 可以用的猜测次数减1</span><br><span class="line">        guessLeft--;</span><br><span class="line">        if (guessNum == num) &#123;</span><br><span class="line">            totalCorrectCount++;</span><br><span class="line">            guessCorrect = true;</span><br><span class="line">            System.out.println(&quot;恭喜你猜对了！这次的数字就是&quot; + num +</span><br><span class="line">                    &quot;。本次你共猜了&quot; + (guessTotal - guessLeft) + &quot;次。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        &#125; else if (guessNum &gt; num) &#123;</span><br><span class="line">            System.out.println(&quot;猜测的数字比目标数字大。&quot;);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            System.out.println(&quot;猜测的数字比目标数字小。&quot;);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    if (!guessCorrect) &#123;</span><br><span class="line">        System.out.println(&quot;本次的目标数字是&quot; + num + &quot;。这次没有猜中。&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">System.out.println(&quot;共进行了&quot; + totalGameCount + &quot;次游戏，其中正确的为&quot; + totalCorrectCount + &quot;次&quot;);</span><br></pre></td></tr></table></figure>
<h1 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h1><h2 id="特点"><a href="#特点" class="headerlink" title="特点"></a>特点</h2></li>
</ul>
</li>
<li>相同类型的变量的集合</li>
<li>可以指定数组元素的个数，最多为int的最大值</li>
<li>元素有固定顺序</li>
<li>每个元素都有索引</li>
<li>如果说变量是一张有名字的纸，可以通过这个名字读写这个变量；数组则是有名字的本子，每页有一个页码，可以通过本子名字和页码读写数组元素<h2 id="创建数组"><a href="#创建数组" class="headerlink" title="创建数组"></a>创建数组</h2></li>
<li><code>dataType[] arrayRefVar = new dataType[arraySize];</code></li>
<li><code>dataType[] arrayRefVar = &#123;value0, value1, ..., valuek&#125;;</code><h2 id="循环数组"><a href="#循环数组" class="headerlink" title="循环数组"></a>循环数组</h2></li>
<li>基本循环<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">double[] myList = &#123;1.9, 2.9, 3.4, 3.5&#125;;</span><br><span class="line">// 打印所有数组元素</span><br><span class="line">for (int i = 0; i &lt; myList.length; i++) &#123;</span><br><span class="line">   System.out.println(myList[i] + &quot; &quot;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>For-Each 循环<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">double[] myList = &#123;1.9, 2.9, 3.4, 3.5&#125;;</span><br><span class="line">// 打印所有数组元素</span><br><span class="line">for (double element:myList) &#123;</span><br><span class="line">   System.out.println(element);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="认识数组"><a href="#认识数组" class="headerlink" title="认识数组"></a>认识数组</h2></li>
<li>理解数组的名与实<ul>
<li>数组的实，是一块地址连续的内存，就像是编号连续的一沓白纸</li>
<li>数组的名，是这个连续内存的第一个内存的地址</li>
<li>数组的变量和基本变量一样，本身是个地址。但与基本变量不一样的是，这个地址的值是数组的名，也就是数组的第一个地址。</li>
</ul>
</li>
<li>数组 = 数组变量 + 数组的实体<ul>
<li>数组变量【索引】就是在数组原有地址的基础上，加上索引，获得想要的元素</li>
<li>索引从0开始，因为数组变量的地址就是数组第一个元素的地址，不需要加<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">int[] book = new int[5];</span><br><span class="line">System.out.println(book[0]);</span><br><span class="line"></span><br><span class="line">比如变量book的地址为8，new int[5]的第一个地址为20，这句语句就是将8指向20</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="数组的长度"><a href="#数组的长度" class="headerlink" title="数组的长度"></a>数组的长度</h2><ul>
<li>数组创建之后，长度不可以改变</li>
</ul>
<h2 id="多维数组"><a href="#多维数组" class="headerlink" title="多维数组"></a>多维数组</h2><ul>
<li>创建<code>String[][] str = new String[3][4];</code></li>
</ul>
<h2 id="数组实战"><a href="#数组实战" class="headerlink" title="数组实战"></a>数组实战</h2><ul>
<li>求某年最好成绩</li>
<li>求某年的平均成绩</li>
<li>求所有年份最好成绩</li>
<li>求某门课历年最好成绩<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line">// 声明六个变量， 分别代表六门科目的成绩</span><br><span class="line">int YuWenIndex = 0;</span><br><span class="line">int ShuXueIndex = 1;</span><br><span class="line">int WaiYuIndex = 2;</span><br><span class="line">int WuLiIndex = 3;</span><br><span class="line">int HuaXueIndex = 4;</span><br><span class="line">int ShengWuIndex = 5;</span><br><span class="line"></span><br><span class="line">int totalScoreCount = 6;</span><br><span class="line"></span><br><span class="line">// 每门课的名字</span><br><span class="line">String[] names = new String[totalScoreCount];</span><br><span class="line">names[YuWenIndex] = &quot;语文&quot;;</span><br><span class="line">names[ShuXueIndex] = &quot;数学&quot;;</span><br><span class="line">names[WaiYuIndex] = &quot;外语&quot;;</span><br><span class="line">names[WuLiIndex] = &quot;物理&quot;;</span><br><span class="line">names[HuaXueIndex] = &quot;化学&quot;;</span><br><span class="line">names[ShengWuIndex] = &quot;生物&quot;;</span><br><span class="line"></span><br><span class="line">Scanner scanner = new Scanner(System.in);</span><br><span class="line"></span><br><span class="line">System.out.println(&quot;请输入共有多少年的成绩：&quot;);</span><br><span class="line"></span><br><span class="line">int yearCount = scanner.nextInt();</span><br><span class="line"></span><br><span class="line">double[][] scores = new double[yearCount][totalScoreCount];</span><br><span class="line"></span><br><span class="line">for (int i = 0; i &lt; yearCount; i++) &#123;</span><br><span class="line">    for (int j = 0; j &lt; totalScoreCount; j++) &#123;</span><br><span class="line">        scores[i][j] = 80 + Math.random() * 20;</span><br><span class="line">        System.out.println(&quot;第&quot; + (i + 1) + &quot;年&quot; + names[j] + &quot;成绩为：&quot; + scores[i][j]);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">boolean cont = true;</span><br><span class="line">while (cont) &#123;</span><br><span class="line">    System.out.println(&quot;请选择要进行的操作：&quot;);</span><br><span class="line">    System.out.println(&quot;1: 求某年最好成绩\n&quot; +</span><br><span class="line">            &quot;2: 求某年的平均成绩\n&quot; +</span><br><span class="line">            &quot;3: 求所有年份最好成绩\n&quot; +</span><br><span class="line">            &quot;4: 求某门课历年最好成绩&quot;);</span><br><span class="line"></span><br><span class="line">    int oprtId = scanner.nextInt();</span><br><span class="line"></span><br><span class="line">    int year = 0;</span><br><span class="line">    switch (oprtId) &#123;</span><br><span class="line">        case 1:</span><br><span class="line">            // 让用户输入指定的年份</span><br><span class="line">            System.out.println(&quot;请输入要计算第几年的最好成绩&quot;);</span><br><span class="line">            year = scanner.nextInt();</span><br><span class="line">            if (year &lt;= 0 || yearCount &lt; year) &#123;</span><br><span class="line">                System.out.println(&quot;非法的年份：&quot; + year);</span><br><span class="line">                cont = false;</span><br><span class="line">                break;</span><br><span class="line">            &#125;</span><br><span class="line">            year = year - 1;</span><br><span class="line">            // 指定年份的最好成绩的编号，开始假设是0</span><br><span class="line">            int bestOfYearScoreId = 0;</span><br><span class="line">            // 循环指定年份的成绩，找出最好的成绩</span><br><span class="line">            // TODO：如果有两门课的成绩一样，而且都是最高的，怎么办？</span><br><span class="line">            for (int i = 1; i &lt; totalScoreCount; i++) &#123;</span><br><span class="line">                if (scores[year][bestOfYearScoreId] &lt; scores[year][i]) &#123;</span><br><span class="line">                    bestOfYearScoreId = i;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(&quot;第&quot; + (year + 1) + &quot;年成绩最好的科目为&quot; + names[bestOfYearScoreId] + &quot;，成绩为&quot; + scores[year][bestOfYearScoreId] + &quot;。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        case 2:</span><br><span class="line">            System.out.println(&quot;请输入要计算第几年的平均成绩&quot;);</span><br><span class="line">            year = scanner.nextInt();</span><br><span class="line">            if (year &lt;= 0 || yearCount &lt; year) &#123;</span><br><span class="line">                System.out.println(&quot;非法的年份：&quot; + year);</span><br><span class="line">                cont = false;</span><br><span class="line">                break;</span><br><span class="line">            &#125;</span><br><span class="line">            year = year - 1;</span><br><span class="line">            double totalCountForAvg = 0;</span><br><span class="line">            for (int i = 0; i &lt; totalScoreCount; i++) &#123;</span><br><span class="line">                totalCountForAvg += scores[year][i];</span><br><span class="line">            &#125;</span><br><span class="line">            double avgOfYear = totalCountForAvg / totalScoreCount;</span><br><span class="line">            System.out.println(&quot;第&quot; + (year + 1) + &quot;年的平均成绩为&quot; + avgOfYear + &quot;。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        case 3:</span><br><span class="line">            int bestYear = 0;</span><br><span class="line">            int bestScore = 0;</span><br><span class="line"></span><br><span class="line">            for (int i = 0; i &lt; yearCount; i++) &#123;</span><br><span class="line">                for (int j = 0; j &lt; totalScoreCount; j++) &#123;</span><br><span class="line">                    if (scores[bestYear][bestScore] &lt; scores[i][j]) &#123;</span><br><span class="line">                        bestYear = i;</span><br><span class="line">                        bestScore = j;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(&quot;所有年度最好成绩为第&quot; + (bestYear + 1) + &quot;年的&quot; + names[bestScore] + &quot;，成绩为&quot; + scores[bestYear][bestScore] + &quot;。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        case 4:</span><br><span class="line">            System.out.println(&quot;请输入科目编号&quot;);</span><br><span class="line">            int subjectId = scanner.nextInt();</span><br><span class="line">            if (subjectId &lt;= 0 || totalScoreCount &lt; subjectId) &#123;</span><br><span class="line">                System.out.println(&quot;非法的科目编号：&quot; + subjectId);</span><br><span class="line">                cont = false;</span><br><span class="line">                break;</span><br><span class="line">            &#125;</span><br><span class="line">            subjectId = subjectId - 1;</span><br><span class="line">            year = 0;</span><br><span class="line">            for (int i = 1; i &lt; yearCount; i++) &#123;</span><br><span class="line">                if (scores[year][subjectId] &lt; scores[i][subjectId]) &#123;</span><br><span class="line">                    year = i;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(&quot;第&quot; + (year + 1) + &quot;年度&quot; + names[subjectId] + &quot;成绩最好，为&quot; + scores[year][subjectId] + &quot;。&quot;);</span><br><span class="line"></span><br><span class="line">            break;</span><br><span class="line">        default:</span><br><span class="line">            cont = false;</span><br><span class="line">            System.out.println(&quot;不支持：&quot; + oprtId + &quot;， 程序结束。&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h1><h2 id="认识基本类型的变量"><a href="#认识基本类型的变量" class="headerlink" title="认识基本类型的变量"></a>认识基本类型的变量</h2><ul>
<li>变量的基本逻辑-有定才有变。在人看来，固定的是名字，变化的是名字对应的值。对计算机来说，固定的是地址，变化的是值。</li>
<li>理解计算机如何使用内存，完成变量的功能<ul>
<li>内存就是一堆白纸，只能通过页码编号访问，也就是内存地址</li>
<li>变量就是使用一个固定的地址加上这个地址对应的内存。计算机通过地址，读写地址对应的内存的值。完成变量的赋值和访问的功能。就好像恶意根据页码编号，在指定的白纸上写字，或者擦掉重新写。</li>
<li>变量的名就是地址，变量的实就是地址对应的内存的值</li>
</ul>
</li>
</ul>

        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="http://haohongbin.gitee.io/blog/page/2/index.html">http://haohongbin.gitee.io/blog/page/2/index.html</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="tag">学习总结</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
      
    </footer>
  </div>
</article>


  <article id="post-Hexo博客正文图片不显示解决方法" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog/2022/07/12/Hexo%E5%8D%9A%E5%AE%A2%E6%AD%A3%E6%96%87%E5%9B%BE%E7%89%87%E4%B8%8D%E6%98%BE%E7%A4%BA%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/">Hexo博客正文图片不显示解决方法</a>
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2022-07-12T08:38:54.000Z" itemprop="datePublished">2022年07月12日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/blog/categories/hexo%E5%8D%9A%E5%AE%A2/">hexo博客</a>
  </div>

      
      
<a href="/blog/2022/07/12/Hexo%E5%8D%9A%E5%AE%A2%E6%AD%A3%E6%96%87%E5%9B%BE%E7%89%87%E4%B8%8D%E6%98%BE%E7%A4%BA%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/#comments" class="article-comment-link">
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>我的版本：  </p>
<img src="/blog/2022/07/12/Hexo%E5%8D%9A%E5%AE%A2%E6%AD%A3%E6%96%87%E5%9B%BE%E7%89%87%E4%B8%8D%E6%98%BE%E7%A4%BA%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/hexo_version.png" class="" title="version">

<p>解决办法：  </p>
<ol>
<li>将_config.yml中的post_asset_folder设置为true</li>
<li>通过命令行<code>hexo new</code>新建文章，将图片放在伴随命令行指令产生的文件夹中</li>
<li>通过如<code>&#123;% asset_img example.jpg This is an example image %&#125;</code>的标签插件来引入图片即可</li>
</ol>

        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="http://haohongbin.gitee.io/blog/page/2/index.html">http://haohongbin.gitee.io/blog/page/2/index.html</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E5%88%86%E4%BA%AB/" rel="tag">分享</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
      
    </footer>
  </div>
</article>


  <article id="post-Hexo-Gitee搭建个人博客" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog/2022/07/12/Hexo-Gitee%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/">Hexo+Gitee搭建个人博客</a>
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2022-07-12T02:19:00.000Z" itemprop="datePublished">2022年07月12日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/blog/categories/hexo%E5%8D%9A%E5%AE%A2/">hexo博客</a>
  </div>

      
      
<a href="/blog/2022/07/12/Hexo-Gitee%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/#comments" class="article-comment-link">
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        
<h1 id="一、前期准备"><a href="#一、前期准备" class="headerlink" title="一、前期准备"></a>一、前期准备</h1><ol>
<li>安装NodeJS环境<br>因为 Hexo 是基于Node.js 的博客框架<br>node下载地址：<a target="_blank" rel="noopener" href="http://nodejs.cn/download/">http://nodejs.cn/download/</a>  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># 验证安装成功</span><br><span class="line">node -v</span><br><span class="line">npm -v</span><br><span class="line"></span><br><span class="line"># 使用淘宝镜像加速器cnpm</span><br><span class="line">npm install -g cnpm --registry=https://registry.npm.taobao.org</span><br></pre></td></tr></table></figure></li>
<li>安装Git  注册gitee账号<h1 id="二、Hexo安装"><a href="#二、Hexo安装" class="headerlink" title="二、Hexo安装"></a>二、Hexo安装</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 全局安装</span><br><span class="line">npm install hexo-cli -g</span><br><span class="line"># 查看hexo版本</span><br><span class="line">hexo -v</span><br></pre></td></tr></table></figure>
<h1 id="三、创建本地博客站点"><a href="#三、创建本地博客站点" class="headerlink" title="三、创建本地博客站点"></a>三、创建本地博客站点</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 初始化一个项目</span><br><span class="line">hexo init hexoblog</span><br><span class="line"># 进入hexoblog项目目录</span><br><span class="line">cd hexoblog</span><br><span class="line"># 安装项目依赖包</span><br><span class="line">npm install</span><br><span class="line"># 启动项目</span><br><span class="line">hexo server</span><br></pre></td></tr></table></figure>
此时访问<a target="_blank" rel="noopener" href="http://localhost:4000/">http://localhost:4000/</a> 即可看到 hexo 默认的页面和一篇“Hello World”默认生成的文章  <h2 id="拓展-项目目录介绍"><a href="#拓展-项目目录介绍" class="headerlink" title="拓展-项目目录介绍"></a>拓展-项目目录介绍</h2></li>
</ol>
<ul>
<li>.deploy　　　　　# 需要部署的文件</li>
<li>node_modules　　# 项目所有的依赖包和插件</li>
<li>public 　　　　　# 生成的静态网页文件</li>
<li>scaffolds 　　　# 文章模板 </li>
<li>source　　　　　# 博客正文和其他源文件等都在这里<ul>
<li>_drafts  　# 草稿</li>
<li>_posts   　# 文章</li>
</ul>
</li>
<li>thems       　　# 主题</li>
<li>_config.yml 　　# 全局配置文件</li>
<li>package.json 　# 项目依赖信息  </li>
</ul>
<p>其他配置信息，可以查看官网：<a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/docs/configuration">https://hexo.io/zh-cn/docs/configuration</a></p>
<h1 id="四、新建博客文章"><a href="#四、新建博客文章" class="headerlink" title="四、新建博客文章"></a>四、新建博客文章</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new &quot;第一篇Hexo blog文章&quot; </span><br></pre></td></tr></table></figure>
<h1 id="五、项目部署到码云"><a href="#五、项目部署到码云" class="headerlink" title="五、项目部署到码云"></a>五、项目部署到码云</h1><ol>
<li>在gitee新建一个仓库</li>
<li>在项目根目录下安装git部署插件<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure></li>
<li>修改配置文件_config.yml  <img src="/blog/2022/07/12/Hexo-Gitee%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/deploy.png" class="" title="deploy"></li>
<li>将项目部署到gitee远程仓库，此时本地文件夹会有一个public文件夹<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo deploy(简写：hexo d)</span><br></pre></td></tr></table></figure></li>
<li>开启Gitee Pages静态网页托管服务</li>
</ol>
<p><strong>注意</strong><br>每次重新上传代码，都需要点击更新按钮重启page服务</p>
<h1 id="六、修改主题"><a href="#六、修改主题" class="headerlink" title="六、修改主题"></a>六、修改主题</h1><p>官网主题：<a target="_blank" rel="noopener" href="https://hexo.io/themes/">https://hexo.io/themes/</a>  </p>
<ol>
<li>下载主题，进入theme目录，将里面的文件复制到自己项目的theme目录下</li>
<li>修改根目录下的配置文件_config.yml</li>
<li>本地启动，访问看是否修改成功</li>
<li>将修改后的项目部署到远程仓库<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">生成静态网站文件</span></span><br><span class="line">hexo g</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">部署到远程仓库</span></span><br><span class="line">hexo d</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">清除hexo的缓存</span></span><br><span class="line">hexo clean</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">采用一键部署方式</span></span><br><span class="line">hexo g --d</span><br></pre></td></tr></table></figure>
<h1 id="七、快速编写文章"><a href="#七、快速编写文章" class="headerlink" title="七、快速编写文章"></a>七、快速编写文章</h1>新建文章时每次都要执行<code>hexo new &quot;blogName&quot;</code> 命令很麻烦<br>可以直接在根目录/source/_posts，创建.md文件进行编写，在文件的顶部添加下面内容就可以了，主要写一个 title 就好了，其他都可以省略<br>```</li>
</ol>
<hr>
<p>title: 文章名称<br>date: 2020-07-30 16:46:07(创建时间)<br>tags: 标签名<br>categories: 分类<br>description: 描述<br>comments: 是否开启评论(true or false)</p>
<hr>
<pre><code>更多hexo使用参考官网：https://hexo.io/docs/
</code></pre>

        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="http://haohongbin.gitee.io/blog/page/2/index.html">http://haohongbin.gitee.io/blog/page/2/index.html</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E5%88%86%E4%BA%AB/" rel="tag">分享</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
      
    </footer>
  </div>
</article>



    <nav id="page-nav">

<a class="extend prev" rel="prev" href="/blog/">上一页</a><a class="page-number" href="/blog/">1</a><span class="page-number current">2</span>
</nav>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-posts"></i> 最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2023/03/14/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%E5%88%97%E8%A1%A8%E5%92%8C%E5%85%83%E7%BB%84/">(no title)</a>
          </li>
        
          <li>
            <a href="/blog/2023/03/09/Java%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95Mock%E7%A5%9E%E5%99%A8/">Java单元测试Mock神器</a>
          </li>
        
          <li>
            <a href="/blog/2023/02/21/Pytest%E6%89%A7%E8%A1%8C%E7%94%A8%E4%BE%8B%E7%9A%84%E5%A4%9A%E7%A7%8D%E6%96%B9%E5%BC%8F/">Pytest执行用例的多种方式</a>
          </li>
        
          <li>
            <a href="/blog/2023/02/20/SQL%E6%9F%A5%E8%AF%A2%E5%9C%BA%E6%99%AF/">SQL查询场景</a>
          </li>
        
          <li>
            <a href="/blog/2023/01/18/MySQL%E5%91%BD%E4%BB%A4%E6%89%8B%E5%86%8C/">MySQL命令手册</a>
          </li>
        
      </ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签云</h3>
    <div class="widget tagcloud">
      <a href="/blog/tags/MySQL/" style="font-size: 15px;">MySQL</a> <a href="/blog/tags/%E5%88%86%E4%BA%AB/" style="font-size: 15px;">分享</a> <a href="/blog/tags/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/" style="font-size: 10px;">单元测试</a> <a href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" style="font-size: 20px;">学习总结</a> <a href="/blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/" style="font-size: 10px;">自动化</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-classify"></i> 分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java/">Java</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF/">Java核心技术</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/hexo%E5%8D%9A%E5%AE%A2/">hexo博客</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/vim/">vim</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E5%90%8E%E7%AB%AF/">后端</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B5%8B%E8%AF%95/">测试</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B5%8B%E8%AF%95%E8%BF%9B%E9%98%B6/">测试进阶</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-archive"></i> 归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/">2023年</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/">2022年</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/MySQL/" rel="tag">MySQL</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%88%86%E4%BA%AB/" rel="tag">分享</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/" rel="tag">单元测试</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="tag">学习总结</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/" rel="tag">自动化</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


  
    

  
</aside>
        
      </div>
      <a id="totop" href="#top"></a>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      <p>
        <a href="/blog/sitemap.xml">网站地图</a>
        <span> | </span><a href="/blog/atom.xml">订阅本站</a>
        <span> | </span><a href="/blog/about/">联系博主</a>
      </p>
      
        <p>
          <i class="fa fa-visitors"></i>
          <i id="busuanzi_container_site_uv"><i id="busuanzi_value_site_uv"></i></i>
          ，
          <i class="fa fa-views"></i>
          <i id="busuanzi_container_site_pv"><i id="busuanzi_value_site_pv"></i></i>
        </p>
      
      <p>
        <span>Copyright &copy; 2023 奉孝.</span>
        <span>Theme by <a href="https://github.com/chaooo/hexo-theme-BlueLake/" target="_blank">BlueLake.</a></span>
        <span>Powered by <a href="https://hexo.io/" target="_blank">Hexo.</a></span>
      </p>
    </div>
  </div>
</footer>

    </div>
  </div>
  
<script src="/blog/js/jquery-3.4.1.min.js"></script>


<script src="/blog/js/search.json.js"></script>


  
<script src="/blog/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog/js/script.js"></script>






  
<script src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>








  



</body>
</html>